﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Demo
{
    class Program
    {
        static void Main(string[] args)
        {
            Main6();
        }
        static void Main1()
        {
            //用户输入正方形边长，用* 打印出实心正方形。
            //如：用户输入5，则输出如下图形。
            //*****
            //*****
            //*****
            //*****
            //*****
            Console.WriteLine("请输入边长：");
            int a = int.Parse(Console.ReadLine());
            for (int i = 0; i < a; i++)
            {
                for (int J = 0; J < a; J++)
                {
                    Console.Write("*");
                }
                Console.WriteLine();
            }
            Console.WriteLine();

        }

        static void Main2()
        {
            string[,] arr = new string[9, 9];
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                for (int j = 0; j <= i; j++)
                {
                    arr[i, j] = (i + 1) + "*" + (j + 1) + "=" + (i + 1) * (j + 1) + " ";
                }
            }
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                for (int j = 0; j < arr.GetLength(1); j++)
                {
                    Console.Write(arr[i, j]);
                }
                Console.WriteLine();
            }
            Console.WriteLine();
        }
        static void Main3()
        {
            //用户输入正方形边长，用* 打印出空心正方形。
            Console.WriteLine();
            int j = int.Parse(Console.ReadLine());
            int[,] arr = new int[j, j];
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                for (int k = 0; k < i; k++)
                {
                    if (i == k || i == arr[j, k] || k == i || k == arr[i, j])
                    {
                        Console.Write("*");
                    }
                    else
                    {
                        Console.Write(" ");
                    }
                }
            }
            Console.WriteLine();
        }
        static void Main4()
        {
            int w = 12;
            int h = 12;
            string zf = "*";
            string kg = " ";
            var arr2 = new int[w, h];
            for (int x = 0; x < w; x++)
            {
                arr2[x, 0] = 1;
                arr2[x, h - 1] = 1;
            }
            for (int y = 0; y < h; y++)
            {
                arr2[0, y] = 1;
                arr2[w - 1, y] = 1;
            }

            for (int y = 0; y < h; y++)
            {
                for (int x = 0; x < w; x++)
                {
                    if (arr2[x, y] > 0) 
                    { Console.Write(zf); 
                    }
                    else { Console.Write(kg); }

                }
                Console.WriteLine();
            }
            Console.ReadKey();
        }
        static void Main5()
        {//打印菱形
            Console.WriteLine("请输入一个数?");
            //这里假设只能输入数字
            int number = Convert.ToInt32(Console.ReadLine());
            int ss = (number / 2);
            bool burz;
            for (int i = 1; i <= number; i++)
            {
                for (int j = 1; j <= number; j++)
                {
                    burz = false;
                    if (Math.Abs(ss) >= j)
                    {
                        Console.Write(" ");
                        burz = true;
                        continue;
                    }
                    if (burz == false)
                    {
                        if (number - Math.Abs(ss) < j)
                        {
                            Console.Write(" ");
                        }
                        else
                        {
                            Console.Write("*");
                        }
                    }
                }
                Console.WriteLine();
                ss--;
            }
            Console.ReadKey();
        }
        static void Main6()
        {
            //打印杨辉三角形（要求打印10行），如下所示：（使用二维数组）
            //1
            //1    1
            //1    2    1
            //1    3    3   1
            //1    4        4    1
            //1    5    10  10   5   1
            int[][] arr = new int[8][]; 
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                arr[i] = new int[i + 1];
            }
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                for (int j = 0; j <=i; j++)
                {
                    if (i == 0 || j == 0)
                    {
                        arr[i][j] = 1;
                    }
                    else if (i ==1 || j == 1 || i == j)
                    {
                        arr[i][j] = 1;
                    }
                    else 
                    {
                        arr[i][j] = arr[i - 1][j] + arr[i - 1][j - 1];
                    }
                }
            }
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                foreach (int item in arr[i])
                {
                    Console.Write(item + " ");
                }
                Console.WriteLine();
            }
        }
        static void Main7()
        {
            //在 Main 方法中创建一个字符串类型的数组，并存入 5 个值，然后将数组中下标是偶数的元素输出。
            int[] arr = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            Console.Write("下标的有:");
            for (int i = 0; i < arr.Length; i++)
            {
                if (i % 2 == 0)
                {
                    Console.Write(arr[i] + " ");
                }
                Console.WriteLine();
            }
        }
        static void Main8()
        {
            //如果一个数组保存元素是有序的（从大到小），
            //向这个数组中插入一个数，
            //使得插入后的数组元素仍然保持有序。

        }
    }
}
